package algorithm.tree;

import algorithm.model.TreeNode;

/**
 * leetcode : https://leetcode.com/problems/same-tree/description/
 * Difficulty : Easy
 *
 * 判断两颗树是否相同，判断依据是值相同并且结构也相同
 * 思路：
 * 使用递归，如代码所示
 * @Author Antony
 * @Since 2018/7/20 15:10
 */
public class SameTree {


    public boolean isSameTree(TreeNode p, TreeNode q) {
        if(p == null && q==null) return true;
        if(p != null && q != null){
            if(p.val==q.val){
                return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
            }else{
                return false;
            }
        }

        return false;
    }
}
